//
// Ephi - simulation of magnetic fields and particles
// Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
// For more information please see http://www.mare.ee/indrek/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

// XXX/TODO: instead of a zillion spheres to "draw" our bezier curve,
// better loft a circle along the bezier curve,

#include "colors.inc"
#include "textures.inc"
#include "transforms.inc"
#include "metals.inc"

global_settings {
  max_trace_level 5
}

background {White}

light_source { <3,2,2>*10, rgb 1 shadowless }
//light_source { <-2,-5,-30>, rgb 0.2 shadowless }

//plane {<0,0,1>,-1 pigment {checker color rgb <0.7,0.5,0.3> White}}

// return {position, slope} array
#macro cubic_bezier_point(B,T)
  #local TT = T*T;
  #local TTT = T*TT;
  array [2] {TTT*B[0]+TT*B[1]+T*B[2]+B[3], 3 * TT * B[0] + 2 * T * B[1] + B[2]}
#end

#macro cubic_bezier(P0,P1,P2,P3)
  #local CC = (P1 - P0) * 3.0;
  #local CB = (P2 - P1) * 3.0 - CC;
  #local CA = (P3 - P0) - CC - CB;
  #local CD = P0;
  array [4] { CA, CB, CC, CD }
#end

// this is quite retarded what we do here but oh well, don't have time for better
#macro draw_cubic_bezier(P0, P1, P2, P3, R, IT)
  #local tit = 0;
  #local b = cubic_bezier(P0, P1, P2, P3);
  #while (tit < 1)
    #local p = cubic_bezier_point(b, tit);
    sphere {
      p[0], R
      pigment { rgb <0.8, 1.0, 0.8> }
    }
    #declare tit = tit + IT;
  #end
#end

#declare StaticRingTexture = texture { pigment { rgb <0.8, 1.0, 0.8> } }
#declare StaticLineTexture = texture { pigment { rgb <0.8, 1.0, 0.8> } }
#declare ArrowTexture = texture { pigment { rgb <1.0, 0.8, 0.8> } }
#declare ArrowTexture2 = texture { pigment { rgb <0.8, 0.8, 1.0> } }

